<template>
  <div class="login-container">
  <div class="login-form">
  <h2 class="form-title">注册<span class="form-subtitle">Welcome!</span></h2>
  <div class="form-group">
  <label for="username">手机号</label>
  <input type="text" id="username" v-model="username" placeholder="请输入手机号">
  </div>
  <div class="form-group">
  <label for="password">密码</label>
  <input type="password" id="password" v-model="password" placeholder="请输入密码">
  </div>
  <div class="form-group">
  <label for="confirmPassword">确认密码</label>
  <input type="password" id="confirmPassword" v-model="confirmPassword" placeholder="请再次输入密码">
  </div>
  <div class="form-button">
  <button class="btn-login" @click="login">注册</button>
  </div>
  <div class="form-footer">
  <router-link to="/login" class="link-create">已有账号，前往登录</router-link>
</div>
  </div>
  </div>
  </template>
  
  <script>
  export default {
  data() {
  return {
  username: "",
  password: "",
  confirmPassword: "",
  };
  },
  methods: {
  login() {
  // 处理注册逻辑
  if (this.password !== this.confirmPassword) {
  alert('两次密码输入不一致，请重新输入！');
  return;
  }
  
    this.$axios
      .get('http://localhost/api/user/create', 
      {
        params: {
          phone: this.username,
          password: this.password
        }
      })
      .then(res => {
        console.log(this.username, this.password);
        console.log(res.data);
        if (res.data.state === true) {
          //console.log(res);
          alert('注册成功');
          this.$router.replace('/login');
        } else {
          alert('注册失败，请重试');
        }
      })
      .catch(err => {
        alert('连接失败,请检查网络');
        console.log('出错了' + err);
      });
  },
  },
  };
  </script>
  
  <style scoped>
 .login-container {
  height: 100vh;
  background-color: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-form {
  width: 400px;
  background-color: rgba(255, 255, 255, 0.6);
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0,0,0,.1);
  padding: 40px;
}

.form-title {
  font-size: 24px;
  line-height: 1.2;
  margin-bottom: 16px;
}

.form-subtitle {
  font-size: 14px;
  color: #ffffff;
  margin-left: 8px;
}

.form-group {
  margin-bottom: 24px;
}

.form-group label {
  display: block;
  font-size: 14px;
  color: #333;
  margin-bottom: 8px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
  display: block;
  width: 100%;
  height: 36px;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px;
  font-size: 14px;
  color: #333;
}

.btn-login {
  background-color: #3a5344;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 12px 24px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color .3s ease-in-out;
}

.btn-login:hover {
  background-color: #83c19d;
}

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  font-size: 14px;
  color: #999999;
}

.form-footer label {
  margin-right: 16px;
}

.link-create {
  color: #1c442c;
  text-decoration: none;
  transition: color .3s ease-in-out;
}

.link-create:hover {
  color: #7a9b87;
}
.form-group {
  display: flex;
  align-items: center;
}

.form-group label {
  width: 80px;
  margin-right: 16px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
  flex: 1;
}
  </style>
  